﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Collections.Generic;

/// <summary>
/// Summary description for clsEmployerDAL
/// </summary>
public class clsEmployerDAL
{
    InstantNaukriDataContextDataContext objInstantNaukriDataContextDataContext = new InstantNaukriDataContextDataContext();
    public clsEmployerDAL()
    {
        //
        // TODO: Add constructor logic here
        //
    }
    public List<IN_TB_EMPLOYER_MST> GetAllEmployer()
    {
        try
        {
            List<IN_TB_EMPLOYER_MST> objIN_TB_Employer = new List<IN_TB_EMPLOYER_MST>();
            objIN_TB_Employer = (from obj in objInstantNaukriDataContextDataContext.IN_TB_EMPLOYER_MSTs
                                 select obj).ToList();
            return objIN_TB_Employer;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public IN_TB_EMPLOYER_MST GetEmployerById(int ID)
    {
        try
        {
            IN_TB_EMPLOYER_MST objIN_TB_EMPLOYER = new IN_TB_EMPLOYER_MST();
            objIN_TB_EMPLOYER = (from obj in objInstantNaukriDataContextDataContext.IN_TB_EMPLOYER_MSTs
                                 where obj.ID == ID
                                 select obj).SingleOrDefault();
            return objIN_TB_EMPLOYER;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public IN_TB_EMPLOYER_MST GetEmployerByUserId(int UserId)
    {
        try
        {
            IN_TB_EMPLOYER_MST objIN_TB_EMPLOYER = new IN_TB_EMPLOYER_MST();
            objIN_TB_EMPLOYER = (from obj in objInstantNaukriDataContextDataContext.IN_TB_EMPLOYER_MSTs
                                 where obj.USER_ID == UserId
                                 select obj).SingleOrDefault();
            return objIN_TB_EMPLOYER;
        }
        catch (Exception)
        {

            throw;
        }
    }

    public int SaveEmployerMst(IN_TB_EMPLOYER_MST objIN_TB_EMPLOYER_MST)
    {
        try
        {
            IN_TB_EMPLOYER_MST objIN_TB_EMPLOYER_MSTD = new IN_TB_EMPLOYER_MST();
            objIN_TB_EMPLOYER_MSTD = (from obj in objInstantNaukriDataContextDataContext.IN_TB_EMPLOYER_MSTs
                                      where obj.ID == objIN_TB_EMPLOYER_MST.ID
                                      select obj).SingleOrDefault();
            if (objIN_TB_EMPLOYER_MSTD != null)
            {
                objIN_TB_EMPLOYER_MSTD.ID = objIN_TB_EMPLOYER_MST.ID;
                objIN_TB_EMPLOYER_MSTD.USER_ID = objIN_TB_EMPLOYER_MST.USER_ID;
                objIN_TB_EMPLOYER_MSTD.EMPLOYER_NAME = objIN_TB_EMPLOYER_MST.EMPLOYER_NAME;
                objIN_TB_EMPLOYER_MSTD.COMPANY_DESCRIPTION = objIN_TB_EMPLOYER_MST.COMPANY_DESCRIPTION;
                objIN_TB_EMPLOYER_MSTD.EMAIL = objIN_TB_EMPLOYER_MST.EMAIL;
                objIN_TB_EMPLOYER_MSTD.MOBILE = objIN_TB_EMPLOYER_MST.MOBILE;
                objIN_TB_EMPLOYER_MSTD.PHONE = objIN_TB_EMPLOYER_MST.PHONE;
                objIN_TB_EMPLOYER_MSTD.STATUS = objIN_TB_EMPLOYER_MST.STATUS;
                objIN_TB_EMPLOYER_MSTD.CREATED_BY = objIN_TB_EMPLOYER_MST.CREATED_BY;
                objIN_TB_EMPLOYER_MSTD.CREATED_ON = objIN_TB_EMPLOYER_MST.CREATED_ON;
                objIN_TB_EMPLOYER_MSTD.MODIFIED_BY = objIN_TB_EMPLOYER_MST.MODIFIED_BY;
                objIN_TB_EMPLOYER_MSTD.MODIFIED_ON = objIN_TB_EMPLOYER_MST.MODIFIED_ON;
                objIN_TB_EMPLOYER_MSTD.DOWNLOAD_TILL = objIN_TB_EMPLOYER_MST.DOWNLOAD_TILL;
                objIN_TB_EMPLOYER_MSTD.LOGIN_TILL = objIN_TB_EMPLOYER_MST.LOGIN_TILL;
                objInstantNaukriDataContextDataContext.SubmitChanges();
                return objIN_TB_EMPLOYER_MST.ID;
            }
            else
            {
                objInstantNaukriDataContextDataContext.IN_TB_EMPLOYER_MSTs.InsertOnSubmit(objIN_TB_EMPLOYER_MST);
                objInstantNaukriDataContextDataContext.SubmitChanges();
                return objIN_TB_EMPLOYER_MST.ID;
            }
        }
        catch (Exception)
        {

            throw;
        }
    }

    public void DeleteEmploye(int EmployeId)
    {
        try
        {
            IN_TB_EMPLOYER_MST objIN_TB_EMPLOYER_MST = new IN_TB_EMPLOYER_MST();
            objIN_TB_EMPLOYER_MST = (from obj in objInstantNaukriDataContextDataContext.IN_TB_EMPLOYER_MSTs
                                     where obj.ID == EmployeId
                                     select obj).SingleOrDefault();
            if (objIN_TB_EMPLOYER_MST != null)
            {
                objInstantNaukriDataContextDataContext.IN_TB_EMPLOYER_MSTs.DeleteOnSubmit(objIN_TB_EMPLOYER_MST);
                objInstantNaukriDataContextDataContext.SubmitChanges();
            }

        }
        catch (Exception)
        {

            throw;
        }
    }

    public List<clsGetEmployerInfo> GetAllEmployerFullInfo()
    {
        try
        {
            List<clsGetEmployerInfo> objclsGetEmployerInfo = new List<clsGetEmployerInfo>();
            objclsGetEmployerInfo = new List<clsGetEmployerInfo>();
            objclsGetEmployerInfo = (from obj in objInstantNaukriDataContextDataContext.IN_TB_EMPLOYER_MSTs
                                     join objUser in objInstantNaukriDataContextDataContext.IN_TB_USERs on obj.USER_ID equals objUser.ID
                                     where objUser.ID == obj.ID
                                     select new clsGetEmployerInfo
                                     {
                                         COMPANY_NAME = obj.EMPLOYER_NAME,
                                         COMPANY_PROFILE = obj.COMPANY_DESCRIPTION,
                                         Download_Till = (DateTime)obj.DOWNLOAD_TILL,
                                         Login_Till = (DateTime)obj.LOGIN_TILL,
                                         EMAIL = objUser.EMAIL,
                                         MOBILE = objUser.MOBILE,
                                         NAME = objUser.NAME,
                                         DOB = (DateTime)objUser.DOB,
                                         EMPLOYER_NAME = objUser.NAME,

                                     }
                                          ).ToList();




            return objclsGetEmployerInfo;



        }
        catch (Exception)
        {

            throw;
        }
    }
}
